/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Gestionpoids.java
 *
 * Created on 2 juin 2011, 20:59:20
 */
package cbrtator.Descripteur;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import rapc.descripteur;

/**
 *
 * @author rikoukiki
 */
public class Gestionpoids extends javax.swing.JPanel {

    private ArrayList<descripteur> ldescripteur = new ArrayList<descripteur>();
    private  JTextField[] liste;

    /** Creates new form Gestionpoids */
    public Gestionpoids() {
        initComponents();
    }

    public Gestionpoids(final ArrayList<descripteur> ldescripteur) {
        this.ldescripteur = ldescripteur;
        
        initComponents();
        
        //tableau contenant la liste des poids
        this.liste = new JTextField[ldescripteur.size()];
        
        int i = 0;
        for ( i=0 ; i < ldescripteur.size(); i++) {           

            //label contenant le nom du descripteur
            JLabel  lab = new JLabel(ldescripteur.get(i).getNom() + " : ");
            lab.setBounds(30, i * 30, 100, 20);
            
            //ajout du textfield ontenant les poids dans l'ordre
            liste[i] =  new JTextField();             
            liste[i].setBounds(130, i * 30, 150, 20);
          

            panel.add(liste[i]);
            panel.add(lab);
            panel.repaint();
            
            
        }
        
        //création du bouton enregistrer
        JButton boutonvalide = new JButton();
        
        //actions du bouton enregistrer c'est a dire ajouter le poids
        boutonvalide.addActionListener(
                
                new ActionListener(){
                    
                    public void actionPerformed(ActionEvent e) 
                    {
                        double valeur=0.0;
                        
                        //Ici mettre en place la sauvegarde
                        for(int i=0;i<liste.length;i++)
                        {
                            //on ajoute les poids
                            valeur = Double.parseDouble(liste[i].getText());                            
                            ldescripteur.get(i).Poids(valeur);
                        }
                    }
                } );
        
        
        //bouton valide
        boutonvalide.setText("Enregistrer");
        boutonvalide.setBounds(130, i * 30, 100, 20);
        
        panel.add(boutonvalide);
                
    }
    
  

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panel = new javax.swing.JPanel();

        setName("Form"); // NOI18N

        panel.setName("panel"); // NOI18N

        javax.swing.GroupLayout panelLayout = new javax.swing.GroupLayout(panel);
        panel.setLayout(panelLayout);
        panelLayout.setHorizontalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        panelLayout.setVerticalGroup(
            panelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel panel;
    // End of variables declaration//GEN-END:variables
}
